#!/usr/bin/env bash

set -x            # print commands before execution
set -o errexit    # always exit on error
set -o pipefail   # honor exit codes when piping
set -o nounset    # fail on unset variables

# clone the repo
git clone https://github.com/electron/electronjs.org site
cd site
npm install

# configure git
git config user.email "electron@github.com"
git config user.name "Electron Bot"

# run each build script independently and commit changes atomically
npm run build-versions
if [[ $(git status --porcelain) != "" ]]; then
  git add .
  git commit -avm "update versions"
fi

npm run build-releases
if [[ $(git status --porcelain) != "" ]]; then
  git add .
  git commit -avm "update releases"
fi

# test it all before pushing
npm test
git push origin HEAD